﻿using AutoMapper;
using Gobang.DataServer;
using Gobang.DataServer.Models;
using Gobang.ToolClass.Model;
using Gobang.ToolClass.Networking;
using Gobang.ToolClass.Networking.UDP;

namespace Gobang.Server.Servers
{
    internal class ServersFactory
    {
        public static string ConnectionString
        {
            set
            {
                SqlSugarFactory.ConnectionString = value;
            }
        }
        public static Lazy<IClientNetworking> ClientLazy { get; private set; }
        public static IClientNetworking Client => ClientLazy.Value;
        public static IMapper Mapper { get; private set; }
        static ServersFactory()
        {
            ClientLazy = new Lazy<IClientNetworking>(() =>
            {
                var client = new UDPClientTool("127.0.0.1", 8090);
                client.Active = true;
                return client;
            });

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap<Gb_UserInfo, UserInfoModel>();
                cfg.CreateMap<UserInfoModel, Gb_UserInfo>();
            });
            Mapper = new Mapper(config);
        }
    }
}
